import { defineStore } from "pinia";
import request from "../utils/request";
import { useUsersStore } from "./usersStore";

interface conversation{
    id:number,
    AI_role:string,
    created_at:Date | string
}

interface State{
    allConversationUserCreated:conversation[] | null
    currentConversationOn:conversation | null
    isLoading:boolean
}

export const useConversationStore=defineStore('conversation',{
    state:():State=>{
        return {
            allConversationUserCreated: null,
            currentConversationOn:null,
            isLoading:false
        }
    },

    getters:{
        getCurrentConversation():conversation | null{
            return this.currentConversationOn
        },

        getAllConversationYourCreated():conversation[] | null{

                return this.allConversationUserCreated

        }
    },

    actions:{
        async updateUserAllConversation(){
            try{
                if(useUsersStore().currentUser === null){
                    return Promise.reject(new Error('无法获取当前登录用户信息'))
                }
                const paramsId = useUsersStore().currentUser?.id;
                this.allConversationUserCreated=await request.get('/api/deepSeek/allConversation',{id:paramsId});
                console.log(this.allConversationUserCreated)
                
            }catch(error){
                return console.error(error)
            }
            
        }
    }
}) 